#!/usr/bin/python
import os
import cgi
import cgitb
# Enable display of python debugging information
cgitb.enable()
# Necessary for browser to interpret as html
print("Content-type: text/html")
print("")
# Handle file upload
fields = cgi.FieldStorage()
if "picture" in fields:
  picture = fields["picture"]
  if picture.file:
    f = open(os.environ["DOCUMENT_ROOT"]
        + "/PictureShare/" 
        + picture.filename, "w")
    f.write(picture.file.read())
# Begin print document
print("<html><head><title>File upload</title></head>")
print("<body>")
print("""
<form action="upload.cgi" method="post" enctype="multipart/form-data">
  <input name="picture" type="file" /><br />
  <input type="submit" value="Submit" />
</form>
""")
print("</body>")
print("</html>")
